/**
 * @file snippet/dp/knapsack/complete_knapsack/main
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 5/18/2022 21:02:51
 **/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = 110, V = 50010;
ll dp[V];
int main() {
  // High rating and good luck!
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, v;
  cin >> n >> v;
  for (int i = 0; i < n; ++i) {
    ll x, c;
    cin >> x >> c;
    for (int j = 0; j <= v; ++j) {
      if (j - x >= 0) dp[j] = max(dp[j], dp[j - x] + c);
    }
  }
  cout << dp[v] << endl;
  return 0;
}
